package SolveQuestions;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class l239 {

    public static void main(String[] args) {
        l239 a = new l239();
        Solution s = a.new Solution();
        Scanner input = new Scanner(System.in);
        int k = input.nextInt();
        int n = input.nextInt();
        int[] nums = new int[n];
        int count = 0;
        while(input.hasNext()){
            nums[count++] = input.nextInt();
        }
        int[] result = s.maxSlidingWindow(nums, k);
        for(int val: result){
            System.out.printf("%d ", val);
        }
    }
    class Solution {
        public int[] maxSlidingWindow(int[] nums, int k) {
            Myque record = new Myque();
            int[] result = new int[nums.length - k + 1];
            for(int i = 0; i < k; i ++) {
                record.offer(nums[i]);
            }
            result[0] = record.getFirst();
            int count = 1;
            for(int i = k; i < nums.length; i ++){
                record.poll(nums[i-k]);
                record.offer(nums[i]);
                result[count++] = record.getFirst();
            }
            return result;
        }
    }

    class Myque{

        private Deque<Integer> ins = new LinkedList<>();
        public void poll(int outNum){
            if(!ins.isEmpty() && outNum == ins.getFirst()){
                ins.removeFirst();
            }
        }

        public void offer(int inNum) {
            while(!ins.isEmpty() && inNum > ins.getLast()) ins.removeLast();
            ins.addLast(inNum);
        }

        public int getFirst() {
            return ins.getFirst();
        }
    }
}
